﻿using System;
using System.Windows;
using Messenia.GUI.ServiceResolver;
using Messenia.Data.Interfaces;
using Messenia.Data.Models;
namespace Messenia.GUI
{
    /// <summary>
    /// Interaction logic for Add.xaml
    /// </summary>
    public partial class AddProject : Window
    {
        //Window1 parentform;
        public AddProject(MainForm parent)
        {
            InitializeComponent();
            var humanResource = NHAOPResolver.Resolve<IHumanResource>().GetAll(0);
            cbStatus.ItemsSource = NHAOPResolver.Resolve<IProjectStatus>().GetAll(0);
            cbResponsible.ItemsSource = humanResource;
            cbCreator.ItemsSource = humanResource;
        }

        private void btnSaveProject_Click(object sender, RoutedEventArgs e)
        {
            var p = new Project
                        {
                            Name = tbProjectName.Text,
                            Description = tbProjectDescr.Text,
                            Responsabile = cbResponsible.SelectedItem as HumanResources,
                            ProjectStatus = cbStatus.SelectedItem as ProjectStatus,
                            Priority = int.Parse(tbPriority.Text),
                            //Creator = cbCreator.SelectedItem != null ? cbCreator.SelectedItem as HumanResources : cbCreator.Items[0] as HumanResources,
                            CreationDate = DateTime.Now,
                            DeadLineDate = DateTime.Now,
                            Rating = int.Parse(tbRating.Text)
                        };
            NHAOPResolver.Resolve<IProject>().Save(p);  
            Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
